#ifndef DOCUMENT_H
#define DOCUMENT_H

#include <QObject>
#include <QVariant>

class Element;
class Line;

struct DocumentProperties;
class DocumentContainer;


typedef QList<QPointer<Element> > ElementCont;

class Document : public QObject
{
    Q_OBJECT
public:
    friend class DocumentContainer;

    // Access methods
    const QString& title();
    void setTitle(const QString& title);

    QPointer<QWidget> ownerView() const;
    void setOwnerView(QPointer<QWidget> ownerView);

    bool isModified() const;

    const ElementCont& elements() const;

    // Element methods
    void addElement(QPointer<Element> element);
    void removeElement(QPointer<Element> element);
    // Creational methods
    QPointer<Line> createLine(const QPointF& start, const QPointF& end);

    // Undo stack
    QPointer<QUndoStack> undoStack() const;

    // Element Properties
    void restoreDefaultDocumentProperties();
    float gridCellSize() const;
    void setCellGridSize(float size);
    float zoom() const;
    void setZoom(float value);

private:
    explicit Document(QObject *parent = 0);
    ElementCont m_elements;
    QString m_title;
    QPointer<QWidget> m_ownerView;
    bool m_bModified;

    DocumentProperties* m_pDocumentProperties;

    QPointer<QUndoStack> m_undoStack;
signals:
    void titleChanged();
    void elementAdded(QPointer<Element> element);
    void elementRemoved(QPointer<Element> element);
    void elementChanged(QPointer<Element> element);
public slots:
    void setModified(bool bModified);
private slots:
    void onElementChanged();
};

Q_DECLARE_METATYPE(Document*)

#endif // DOCUMENT_H
